package lc;

import ch2linkedlist.Chapter;
import ch2linkedlist.ListNode;

public class RemoveDuplicatesFromSortedList {
    public ListNode deleteDuplicates(ListNode head) {
    	if (head == null) {
    		return null;
    	}
    	
        ListNode n = head;
        while (n.next != null) {
        	if (n.next.val == n.val) {
        		n.next = n.next.next;
        	}
        	else {
        		n = n.next;
        	}
        }
    	return head;
    }
    
    public static void main(String ...strings) {
    	RemoveDuplicatesFromSortedList sol = new RemoveDuplicatesFromSortedList();
    	ListNode head = Chapter.createSampleList(new int [] {1, 1, 2, 3, 3});
    	Chapter.print(head);
    	ListNode deleteDuplicates = sol.deleteDuplicates(head);
    	Chapter.print(deleteDuplicates);
    }

}
